package com.budwk.app.sqfwV2.enums;

import com.budwk.app.sqfwDoc.codeGenerator.excelGenerate.BaseTemplateExcelGenerator;
import com.budwk.app.sqfwV2.component.BinyangStreetComponent;
import com.budwk.app.sqfwV2.generator.binyangStreet.excel.CampusTrainingOffExcel;
import com.budwk.app.sqfwV2.generator.binyangStreet.excel.EnterpriseSafetyInvestigationExcel;
import com.budwk.app.sqfwV2.generator.binyangStreet.excel.LargeCompanySafeGenerator;
import com.budwk.app.sqfwV2.generator.binyangStreet.excel.logisticsWarehouseExcelGenerator;
import lombok.Getter;

import java.util.Arrays;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;

/**
 * 宾阳街道文件对应枚举
 */
@Getter
public enum BinYangFileServiceEnum {

    ONE_EXCEL("大型企业", "large_enterprises_hazards_safety_check", new LargeCompanySafeGenerator(),
            "sqfwV2/binyangStreet/largeCompanySafeExcel.xlsx", "大型企业安全检查隐患清单", "大型企业", "", "/preview/safety/by/大型企业安全检查_excel.png"),
    TWO_EXCEL("企业安全生产主体", "by_enterprise_safety_production_entities", new EnterpriseSafetyInvestigationExcel(),
            "sqfwV2/binyangStreet/enterpriseSafetyInvestigation.xlsx", "企业安全生产主体责任隐患清单", "企业安全生产主体", "", "/preview/safety/by/企业安全生产主体_excel.png"),
    THREE_EXCEL("校外培训机构", "campus_training_off_excel", new CampusTrainingOffExcel(),
            "sqfwV2/binyangStreet/campusTrainingOffLedger.xlsx", "宾阳街道校外培训机构隐患清单", "校外培训机构", "", "/preview/safety/by/校外培训机构消防_excel.png"),
    FORE_EXCEL("物流仓储", "binyang_logistics_warehouse_excel", new logisticsWarehouseExcelGenerator(),
            "sqfwV2/binyangStreet/logisticsWarehouseExcel.xlsx", "物流仓储隐患清单", "物流仓储", "", "/preview/safety/by/物流仓储_excel.png"),


    ONE_PDF("大型企业安全排查", "large_enterprises_hazards_safety_check_pdf", null,
            "sqfwV2/binyangStreet/largeCompanySafeWord.docx", "大型企业安全排查", "大型企业", "sqfwV2/binyangStreet/template/largeCompanySafeWordTemplate.docx", "/preview/safety/by/大型企业_pdf.png"),
    TWO_PDF("企业安全生产主体", "by_enterprise_safety_production_entities_doc", null,
            "sqfwV2/binyangStreet/enterpriseSafetyInvestigation.docx", "企业安全生产主体", "企业安全生产主体", "sqfwV2/binyangStreet/template/enterpriseSafetyInvestigationTemplate.docx", "/preview/safety/by/企业安全_pdf.png"),
    THREE_PDF("校外培训机构", "campus_training_off_doc", null,
            "sqfwV2/binyangStreet/campusTrainingOffDoc.docx", "校外培训机构", "校外培训机构", "sqfwV2/binyangStreet/campusTrainingOffDocTemplate.docx", "/preview/safety/by/校外培训_pdf.png"),
    FORE_PDF("物流仓储", "binyang_logistics_warehouse_doc", null,
            "sqfwV2/binyangStreet/logisticsWarehouseDoc.docx", "物流仓储安全隐患排查标准", "物流仓储", "sqfwV2/binyangStreet/template/logisticsWarehouseDocTemplate.docx", "/preview/safety/by/物流仓储_pdf.png");

    private final String name;

    private final String code;

    private final BaseTemplateExcelGenerator service;

    private final String filePath;

    private final String fileName;

    private final String label;

    private final String templatePath;

    private final String previewImage;

    BinYangFileServiceEnum(String name, String code, BaseTemplateExcelGenerator service, String filePath, String fileName, String label, String templatePath, String previewImage) {
        this.name = name;
        this.code = code;
        this.service = service;
        this.filePath = filePath;
        this.fileName = fileName;
        this.label = label;
        this.templatePath = templatePath;
        this.previewImage = previewImage;
    }

    public static List<BinYangFileServiceEnum> getAllExcel() {
        return List.of(ONE_EXCEL, TWO_EXCEL, THREE_EXCEL, FORE_EXCEL);
    }

    public static List<BinYangFileServiceEnum> getAllPdf() {
        return List.of(ONE_PDF, TWO_PDF, THREE_PDF, FORE_PDF);
    }

    /**
     * @param code
     * @return
     */
    public static BaseTemplateExcelGenerator getService(String code) {
        Optional<BinYangFileServiceEnum> optional = Arrays.stream(values()).filter(e -> e.getCode().equals(code)).findFirst();
        return optional.map(BinYangFileServiceEnum::getService).orElse(null);
    }

    /**
     * @param code
     * @return
     */
    public static BinYangFileServiceEnum getByCode(String code) {
        Optional<BinYangFileServiceEnum> optional = Arrays.stream(values()).filter(e -> e.getCode().equals(code)).findFirst();
        return optional.orElse(null);
    }

    /**
     * @param label 按照标签获取所有的code
     * @return
     */
    public static List<String> getCodeByLabel(String label) {
        return Arrays.stream(values()).filter(e -> label.equals(e.getLabel())).map(BinYangFileServiceEnum::getCode).collect(Collectors.toList());
    }

    /**
     * @param label 标签
     * @return
     */
    public static BinYangFileServiceEnum getByLabel(String label, String district, String county) {
        // 必须是观山湖区下的金阳街道过来的数据
        if (!BinyangStreetComponent.isBinYangCity(district, county)) {
            return null;
        }
        // pdf选项
        List<BinYangFileServiceEnum> list = getAllPdf();
        Optional<BinYangFileServiceEnum> optional = list.stream().filter(e -> e.getLabel().equals(label)).findFirst();
        return optional.orElse(null);
    }
}
